home *** CD-ROM | disk | FTP | other *** search
- Path: lrz-muenchen.de!news
- From: watzka@stat.uni-muenchen.de (Kurt Watzka)
- Newsgroups: comp.lang.c
- Subject: Re: help with strcmp
- Date: 2 Apr 1996 12:39:21 GMT
- Organization: Leibniz-Rechenzentrum, Muenchen (Germany)
- Distribution: world
- Message-ID: <4jr75p$onk@sparcserver.lrz-muenchen.de>
- References: <4jpiek$lp6@blaze.cs.jhu.edu> <316196CB.1125@diagram.fr>
- NNTP-Posting-Host: sun2.lrz-muenchen.de
-
- Jean-Dominique BOISSE <jdbo@diagram.fr> writes:
-
- >> if ( strcasecmp(fp, "<action>\n") == 0) /* the coredump is here */
-
- > I think that you must use strncasecmp instead of strcasecmp, like this
-
- > strncasecmp(fp,"<action>\n",40)
-
- > This function will only read 40 characters from fp for the test.
-
- > You can also put a '\0' at the very end of fp (fp[40]) and still use
- > strcasecmp, but read only 39 chars from handle.
-
- fgets() always reads a C string, even if it does not read a whole line
- in some cases.
-
- We cannot say much about the behaviour of strcasecmp() and strncasecmp()
- on a given machine, but if they are just implementations of strcmp() and
- strncmp() that ignore differences in case when comparing upper and lower
- case letters, this is nonsense.
-
- strcmp() and strncmp() are designed to handle C strings, so they know how
- to treat '\0' in a string. Otherwise
-
- int STRCMP(const char *s1, const char *s2)
- {
- size_t sz1 = strlen(s1), sz2 = strlen(s2);
- return strncpm(s1, s2, sz1 < sz2 ? sz1 : sz2);
- }
-
- would be a common replacement for the then useless strcmp() function.
-
- Kurt
- --
- | Kurt Watzka Phone : +49-89-2180-6254
- | watzka@stat.uni-muenchen.de
-